﻿using AutoMapper;
using MediatR;
using T.S.BaseData.Api.AppClinet.Commend.proce;
using T.S.BaseData.Api.Dto.Proce;
using T.S.BaseData.Domain.Entity;
using T.S.BaseData.ErrorCode;
using T.S.BaseData.Infrastructure.Base;

namespace T.S.BaseData.Api.AppClinet.CommendHand.proce
{
    public class ProceSetCommandHandle : IRequestHandler<ProceSetCommand, ApiResult<List<GetProceDto>>>
    {
        private readonly IBaseRepository<Processing> proceRepo;
        private readonly IMapper mapper;

        public ProceSetCommandHandle(IBaseRepository<Processing> proceRepo, 
            IMapper mapper)
        {
            this.proceRepo = proceRepo;
            this.mapper = mapper;
        }

        public Task<ApiResult<List<GetProceDto>>> Handle(ProceSetCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<GetProceDto>> result = new ApiResult<List<GetProceDto>>();
            var proce = proceRepo.GetAll().Where(x=>x.GoodsId == request.GoodsId);

            var model = mapper.Map<List<GetProceDto>>(proce);

            result.Code = ApiEnums.Success;
            result.Data = model;
            result.Meg = "显示成功";

            return Task.FromResult(result);

        }
    }
}
